<html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="content-type">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
        <title>
            js调用java
        </title>
        <style type="text/css">
            .musicbtn {
                width: 80px;
                height: 40px;
                font-size: 16px;
                line-height: 40px;
                color: #fff;
                background-color: rgba(25,225,225,.5);
                text-align: center;
                border-radius: 20px;
                position: absolute;
                top: 40%;
                right: 20px;
            }
            .btn {
                height: 40px;
                line-height: 40px;
                font-size: 16px;
                background-color: #ffd541;
                color: #fff;
                width: 180px;
                text-align: center;
                border-radius: 5px;
                margin-top: 10px;
            }
        </style>
    </head>
    
    <body>
    <div class="musicbtn" id="playBtn">播放音乐</div>
    <audio src="./music.mp3" preload="" id="media"></audio>
       
            <div id="show">
            </div>
            <div id="show2">
            </div>
            <div id="show3">
            </div>
        
            <div class="btn" data-type="0">登录</div>
       
            <div class="btn" data-type="1">注册</div>
       
            <div class="btn" data-type="2">首页</div>
        
            <div class="btn" data-type="3">投资列表 </div>
       
            <div class="btn" data-type="4">项目详情</div>
        
            <div class="btn" data-type="5">我要借款</div>
       
            <div class="btn" data-type="6">我的投资</div>
       
            <div class="btn" data-type="7">投资详情</div>
       
            <div class="btn" data-type="8">团宝箱</div>
        
            <div class="btn" data-type="9">现金红包</div>
       
            <div class="btn" data-type="10" >投资红包 </div>
        
            <div class="btn" data-type="11" >加息卷</div>
       
            <div class="btn" data-type="12" >提现卷</div>
       
            <div class="btn" data-type="13" >抵扣卷</div>
       
            <div class="btn" data-type="14" >签到卡</div>
       
            <div class="btn" data-type="15" >精美礼品</div>
       
            <div class="btn" data-type="16" >充值 </div>
       
            <div class="btn" data-type="17" >安全中心</div>
       
            <div class="btn" data-type="18" >手机验证</div>
        
            <div class="btn" data-type="19" >身份证验证</div>
        
            <div class="btn" data-type="20" >我的财富</div>
        
            <div class="btn" data-type="21" >邀请好友</div>
        
            <div class="btn" data-type="22" >活动分享</div>
        
            <div class="btn" data-type="23" >WE计划</div>
        
            <div class="btn" data-type="24" > WE计划 * 项目详情</div>
        
            <div class="btn" data-type="25" > 我的投资详情（WE计划）</div>
        
    </body>
    <script src="./zepto-animate.js" type="text/javascript" charset="utf-8"></script>
    <script src="./jsbridge.js" type="text/javascript" charset="utf-8"></script>
     <!-- <script src="./js/index.js" type="text/javascript" charset="utf-8"></script> -->

    <script>
        (function() {
            // window.location.href = "./html/demo-0620.html";
            var music = document.getElementById("media");
            var obj = document.getElementById("playBtn");
            var isLogin = false;

            function triggerMusic() {

                if ($(".musicbtn").attr("data-paused") == 0) {
                    pauseMusic();
                    $(".musicbtn").attr("data-status", "stopped");
                } else {
                    playMusic();
                    $(".musicbtn").attr("data-status", "playing");
                }
            }

            function playMusic() {
                // music.play();
                var musicUrl = "http://121.13.249.210:9006/weixin/dist/music/music.mp3";
                Jsbridge.appPlayMusic(musicUrl);
                obj.innerHTML = "暂停播放";
                $(".musicbtn").attr("data-paused", 0);
            }

            function pauseMusic() {
                // music.pause();
                Jsbridge.appStopMusic();
                obj.innerHTML = "播放音乐";
                $(".musicbtn").attr("data-paused", 1);
            }
            obj.addEventListener("click", triggerMusic, false);
            
            var isLogin = false;
            /* var str = navigator.userAgent;
             var arr = str.match(/\[([^\[\]]*)\]/);*/
            /*
                        initCallback：初始化回调
                        loginTokenCallback：获取loginToken用于登录
                        webonResumeCallback：打开活动页回调
                        webonPauseCallback：离开活动页回调
                        webonPauseCallback：销毁进程回调
                    **/
            Jsbridge.appLifeHook(function(message) {
                console.info("app-page-init--");

            }, function(data) {
                /*        {
                            "Token": "",
                            "ReturnCode": 4,
                            "ReturnMessage": "登录已失效，请重新登录",
                            "Data": ""
                        } {
                            "Token": "",
                            "ReturnCode": 1,
                            "ReturnMessage": "成功",
                            "Data": {
                                "LoginToken": "5AF81C2720EA40AB776CCA120EC98BFC"
                            }
                        }*/
                data = JSON.parse(data);
                if (data.ReturnCode == 1) {
                    var loginToken = data.Data.LoginToken;
                    //调用后台接口登录
                    // appLogin(loginToken);
                    // var url = "http://121.13.249.210:9006/ajaxCross/Login.ashx?Action=UserLogin"; //106测试地址
                    // var url = "http://hd.tuandai.com/ajaxCross/Login.ashx?Action=UserLogin"; //正式地址
                    var url = "http://10.100.11.110:9006/ajaxCross/Login.ashx?Action=UserLogin"; //110地址
                    Jsbridge.appLogin(url, loginToken, function(result) {
                        $("#show2").html("success------" + JSON.stringify(result));
                        if (result.Status == 1) {
                            isLogin = true;
                        } else {
                            isLogin = false;
                        }
                    }, function(e) {
                        alert("error--" + JSON.stringify(e));
                    });

                } else {
                    //没有获得到loginToken，跳转到登录页面
                    // Jsbridge.toAppLogin();
                    // $("#show3").html(data.ReturnMessage);

                }

            }, function(data) {
                // 打开页面播放音乐
                if ($(".musicbtn").attr("data-status") !== "stopped") {
                    playMusic();
                }
            }, function(data) {
                // 离开页面停止播放音乐
                pauseMusic();
            }, function(data) {
                pauseMusic();

            });

            /*if(GetQueryString('type') == 'mobileapp') {
                //app 判断是否为新版本
                if(Jsbridge.isNewVersion()) {
                    
                }else{
                    //旧版本app 按照原来的方式登录
                }
            }else{
                //微信或者浏览器 按照原来的方式登录
                // var isWeiXin = navigator.userAgent.toLowerCase().indexOf("micromessenger") != -1;
            }*/


            function GetQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
            /*function appLogin(loginToken) {
                //'http://121.13.249.210:9006//weixin/Yuanxiao20160218/ajax/ajax.ashx?Action=AjaxLogin'
                var url = "http://121.13.249.210:9006/ajaxCross/Login.ashx?Action=UserLogin"; //106测试地址
                // var url = "http://hd.tuandai.com/ajaxCross/Login.ashx?Action=UserLogin"; //正式地址

                $.ajax({
                    url: url,
                    data: {
                        appActivityToken: loginToken
                    },
                    dataType: 'json',
                    type: 'post',
                    success: function(result) {
                        console.info("result-------", result);
                        if(result.Status == 1) {
                            isLogin = true;
                        }else{
                            isLogin = false;
                        }
                        
                    }
                });
            }*/

            $(".btn").on('click', function() {
                var type = $(this).attr('data-type');
                switch (parseInt(type)) {
                    case 0:
                        //跳转到登录
                        //判断是否为新版本的app， 是的话用新方式跳转，否则按照原来的方式跳转
                        /* if (Jsbridge.isNewVersion()) {
                             Jsbridge.toAppLogin();
                         }*/
                        Jsbridge.toAppLogin();
                        break;
                    case 1:
                        //跳转到注册
                        Jsbridge.toAppRegister();
                        break;
                    case 2:
                        //跳转到首页
                        Jsbridge.toAppMainPage();
                        break;
                    case 3:
                        //投资列表
                        if (isLogin) {

                            Jsbridge.toAppInvestList();
                        } else {
                            Jsbridge.toAppLogin();
                        }
                        break;
                    case 4:
                        // 项目详情 
                        /**
                            toAppInvestDetails(Id, TypeId, SubTypeId, ProfitTypeId, XmbSubType)
                            Id 41a72bbea40a42beaae443f292e6d5de
                            TypeId 10
                            SubTypeId 0
                            ProfitTypeId 0
                        */
                        Jsbridge.toAppInvestDetails('41a72bbea40a42beaae443f292e6d5de', 10, 0, 0);
                        break;
                    case 5:
                        // 我要借款
                        Jsbridge.toAppLoan();
                        break;
                    case 6:
                        // 我的投资
                        Jsbridge.toAppMyInvest();
                        break;
                    case 7:
                        //投资详情
                        /**
                            toAppMyInvestDetail(ProjectId,Type,InvestId,ProfitTypeId,IsWePlanX,SubTypeId)
                            数据1
                            InvestId c58ac9471e2348a8876b7d050ab48109
                            ProjectId b83d65b899244b2187a2772bcf77f083
                            Type 11
                            ProfitTypeId 0
                            IsWePlanX false
                            数据2
                            InvestId a0cfc10ecbd44bf1a5afa6f2de43e7d7
                            ProjectId
                            Type 100
                            ProfitTypeId 0
                            IsWePlanX false
                            数据3
                            InvestId 20387f5ae21749f5b83537fdcdc93c04
                            ProjectId
                            Type 100
                            ProfitTypeId 0
                            IsWePlanX true
                        */
                        Jsbridge.toAppMyInvestDetail('b83d65b899244b2187a2772bcf77f083', 11, 'c58ac9471e2348a8876b7d050ab48109', 0, false, '');
                        break;
                    case 8:
                        // 团宝箱
                        Jsbridge.toAppTBX();
                        break;
                    case 9:
                        // 现金红包
                        Jsbridge.toAppCashRedPacket();
                        break;
                    case 10:
                        // 投资红包
                        Jsbridge.toAppOrdinaryRedPacket();
                        break;
                    case 11:
                        // 加息卷
                        Jsbridge.toAppKasiRedPacket();
                        break;
                    case 12:
                        // 提现卷
                        Jsbridge.toAppWithdrawalRoll();
                        break;
                    case 13:
                        // 抵扣卷
                        Jsbridge.toAppRebateRedPacket();
                        break;
                    case 14:
                        // 签到卡
                        Jsbridge.toAppSingInRoll();
                        break;
                    case 15:
                        // 精美礼品
                        Jsbridge.toAppPresent();
                        break;
                    case 16:
                        // 充值
                        Jsbridge.toAppRecharge();
                        break;
                    case 17:
                        // 安全中心
                        Jsbridge.toAppSecurityCenter();
                        break;
                    case 18:
                        // 手机验证
                        Jsbridge.toAppMobileVerify();
                        break;
                    case 19:
                        // 身份证验证
                        Jsbridge.toAppIdentityVerify();
                        break;
                    case 20:
                        // 我的财富
                        Jsbridge.toAppPersonalCenter();
                        break;
                    case 21:
                        // 邀请好友
                        Jsbridge.toAppInviteFriend();
                        break;
                    case 22:
                        // 活动分享
                        Jsbridge.toActivityAppInviteFriend();
                        break;
                    case 23:
                        // WE计划
                        Jsbridge.toAppWePlan();
                        break;
                    case 24:
                        // WE计划 * 项目详情
                        /**
                            toAppWePlanDetail(productId) 
                        */
                        Jsbridge.toAppWePlanDetail('1cec2540001247c3831fd83216ddbc55');
                        break;
                    case 25:
                        // 我的投资详情（WE计划）
                        Jsbridge.toAppMyInvestDetail('', 100, '20387f5ae21749f5b83537fdcdc93c04', 0, true);
                        break;


                }
            });



        })();
    </script>

</html>